import { COLOR, formarColor, CreatePosition } from '../Config'

class Label {
    constructor(Entity, options, defaultOptions) {
        if (!Entity) {
            throw new Error('Entity 参数不能为空');
        }
        this._defaultOptions = defaultOptions;
        this._Entity = Entity;
        this.options = options
    }
    _RenderLabel() {
        let _Text = this._options.text || '';
        let _Color = this._options.color || COLOR.LIGHT_BLUE;
        let _BGColor = this._options.BGColor || COLOR.DARK_GREEN;
        let _fontSize = this._options.fontSize || 16;
        let _show = this._options.Show === undefined || this._options.Show
        let _horizontal = (this._options.horizontal && this._options.horizontal.toUpperCase()) || 'CENTER';
        let _vertical = (this._options.vertical && this._options.vertical.toUpperCase()) || 'CENTER';;
        let _Offset = this._options.offset || [0, 0];

        this._Entity.label = {
            text: _Text,
            show: _show,
            font: _fontSize + 'px Source Han Sans CN',
            showBackground: !!_BGColor,
            fillColor: formarColor(_Color),
            backgroundColor: formarColor(_BGColor),
            style: Cesium.LabelStyle.FILL,
            horizontalOrigin: Cesium.HorizontalOrigin[_horizontal],
            verticalOrigin: Cesium.VerticalOrigin[_vertical],
            pixelOffset: new Cesium.Cartesian2(_Offset[0], _Offset[1]),
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
        }
    }
    set options(options) {
        if (!options) {
            options = this._defaultOptions || {};
        };
        if (typeof options == 'string') {
            let _t = options;
            options = { text: _t, }
        };
        if (options.text) {
            this._options = options;
            this._RenderLabel();
        }
    }
    get options() {
        return this._options
    }

    set show(value) { this._Entity.Label.show = value; }
    get show() { return this._Entity.Label.show }

    set color(value) { this._Entity.Label.fillColor = formarColor(value); }
    get color() { return this._Entity.Label.fillColor }

    set BGColor(value) { this._Entity.Label.backgroundColor = formarColor(value); }
    get BGColor() { return this._Entity.Label.backgroundColor }

    set horizontal(value) { this._Entity.Label.horizontalOrigin = Cesium.HorizontalOrigin[value.toUpperCase() || 'CENTER']; }
    get horizontal() { return this._Entity.Label.horizontalOrigin }

    set vertical(value) { this._Entity.Label.verticalOrigin = Cesium.VerticalOrigin[value.toUpperCase() || 'CENTER']; }
    get vertical() { return this._Entity.Label.verticalOrigin }

    set offset(value) { this._Entity.Label.pixelOffset = new Cesium.Cartesian2(value[0], value[1]); }
    get offset() { return [this._Entity.Label.pixelOffset.x, this._Entity.Label.pixelOffset.y] }

}

export default Label;